package com.gis.servlet.find;

import cn.hutool.core.util.StrUtil;
import com.gis.bean.Find;
import com.gis.dao.FindDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author t-zhaoheng
 * @since 2022/5/16
 */
@WebServlet("/find/update.do")
public class FindUpdateServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

  /**
   * @see HttpServlet #HttpServlet()
   */
  public FindUpdateServlet() {
    super();
    // TODO Auto-generated constructor stub
  }

  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String id = request.getParameter("id");
    Integer goodsType = Integer.parseInt(request.getParameter("goodsType"));
    String findTime = request.getParameter("findTime");
    Double lng = Double.parseDouble(request.getParameter("lng"));
    Double lat = Double.parseDouble(request.getParameter("lat"));
    String address = request.getParameter("address");
    String description = request.getParameter("description");
    String fileName = request.getParameter("fileName");

    Find find = new Find();
    find.setId(Integer.parseInt(id));
    find.setGoodsTypeId(goodsType);
    find.setFindTime(findTime);
    find.setLng(lng);
    find.setLat(lat);
    find.setAddress(address);
    find.setDescription(description);
    if (StrUtil.isNotEmpty(fileName)) {
      find.setFileName(fileName);
    }
    int i = FindDao.getInstance().updateFind(find);
    if (i > 0) {
      ResponseUtil.writeJson(response, RestResponse.success(Constant.UPDATE_SUCCESS));
    } else {
      ResponseUtil.writeJson(response, RestResponse.fail(Constant.UPDATE_FAILED));
    }
  }

  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
  }
}
